package com.basker.pisces.service.config;

import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.basker.pisces.service.message.converter.CustomFastJsonHttpMessageConverter;
import com.basker.pisces.service.message.converter.CustomResourceHttpMessageConverter;

@Configuration
public class HttpMessageConverterConfig {

    /**
     * <li>添加fastjson作为application/json默认的解码器.
     * <li>添加支持文件下载的resouce解码器.
     *
     * @return
     */
    @Bean
    public HttpMessageConverters httpMessageConverters() {
        FastJsonHttpMessageConverter fastConverter = new CustomFastJsonHttpMessageConverter();
        CustomResourceHttpMessageConverter resourceConverter = new CustomResourceHttpMessageConverter();

        // HttpMessageConverters会创建许多默认的解码器
        return new HttpMessageConverters(fastConverter, resourceConverter);
    }
}
